// 阿里大鱼SDK
package alidayu

import (
	"encoding/json"
	"net/url"

	"github.com/xgggh/open/gotop/base"
)

type Client struct {
	*base.Client
}

func NewClient(appKey, appSecret string) *Client {
	return &Client{
		Client: base.NewClient(appKey, appSecret),
	}
}

func (c *Client) SendTemplateSMS(tsms *TemplateSMS) (*base.Response, error) {
	params := make(url.Values)

	params.Set("sms_type", "normal")
	params.Set("sms_free_sign_name", tsms.FreeSignName)
	params.Set("rec_num", tsms.RecNum)
	params.Set("sms_template_code", tsms.TemplateCode)

	if len(tsms.Extend) > 0 {
		params.Set("extend", tsms.Extend)
	}
	if tsms.Param != nil && len(tsms.Param) > 0 {
		b, _ := json.Marshal(&tsms.Param)
		params.Set("sms_param", string(b))
	}

	return c.PostForm("alibaba.aliqin.fc.sms.num.send", params)
}
